package cn.chenfyuan.demoapplication.controller;

import javax.annotation.Resource;

import cn.chenfyuan.demoapplication.entity.Role;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import cn.chenfyuan.demoapplication.service.RoleService;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author linweijian
 * @since 2018-08-31
 */
@RestController
@RequestMapping("/role")
public class RoleController {

	@Resource
	private RoleService roleService;

	@RequestMapping(value = "/", method = RequestMethod.GET)
	public ResponseEntity<?> queryPage(@RequestParam int pageNum, @RequestParam int pageSize, @ModelAttribute Role vo) {
			Page<Role> page = roleService.selectPage(new Page<>(pageNum, pageSize), vo);
			return new ResponseEntity<>(page, HttpStatus.OK);

	}

	@RequestMapping(value = "/", method = RequestMethod.POST)
	public ResponseEntity<?> add(@RequestBody Role vo) {
			return new ResponseEntity<>(roleService.insert(vo),HttpStatus.OK);
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	public ResponseEntity<?> delete(@PathVariable("id") String id) {
			return new ResponseEntity<>(roleService.deleteById(id),HttpStatus.OK);

	}

	@RequestMapping(value = "/", method = RequestMethod.PUT)
	public ResponseEntity<?> update(@RequestBody Role vo) {
			return new ResponseEntity<>(roleService.updateById(vo),HttpStatus.OK);
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResponseEntity<?> get(@PathVariable("id") String id) {
	    return new ResponseEntity<>(roleService.selectById(id),HttpStatus.OK);
	}


}

